﻿using System;
using System.Data;

namespace NetFramework.DataAccess.EntityBuilder
{
    internal class DataRowDataSource : IDataSource
    {
        private DataRow datarow;
        private int columnCount;
        private DataColumnCollection columns;

        public DataRowDataSource(DataRow datarow)
        {
            this.datarow = datarow;

            this.columnCount = this.datarow.Table.Columns.Count;
            this.columns = this.datarow.Table.Columns;
        }

        #region IDataSource Members

        public object this[string columnName]
        {
            get { return this.datarow[columnName]; }
        }

        public object this[int columnIndex]
        {
            get { return this.datarow[columnIndex]; }
        }

        public int ColumnCount
        {
            get { return this.columnCount; }
        }

        public string GetName(int index)
        {
            return columns[index].ColumnName;
        }

        public Type GetColumnType(int index)
        {
            return this.columns[index].DataType;
        }
        #endregion
    }
}
